<?php
require_once dirname(__FILE__) . '/../../php/paths.cfg.php';
$dir = TEXYLA_IMAGE_FILE_ROOT;
$files = scandir($dir);
$images = array();

foreach ($files as $file) {
	if (filetype("$dir/$file") == "file") {
		$size = getimagesize("$dir/$file");
		
		if ($size) {
			// rozměry
			$width = $size[0];
			$height = $size[1];
			
			if ($width > $height) {
				$thumbWidth = min(80, $width);
				$thumbHeight = round($height * $thumbWidth / $width);
			} else {
				$thumbHeight = min(80, $height);
				$thumbWidth = round($width * $thumbHeight / $height);
			}
			
			$images[] = array(
				"name" => ereg_replace("\.[^\.]+$", "", $file), // odstraní příponu
				"src" => $file,
				"alt" => "Image $file",
				"thumbSrcVar" => urlencode($file),
				"thumbWidth" => $thumbWidth,
				"thumbHeight" => $thumbHeight
			);
		}
	}
}


echo json_encode(array(
	"images" => $images
));
